import { HYEventStore } from 'hy-event-store'
import { getRankings } from '../service/topMusic_api'

const rankingMap = ['newRanking', 'hotRanking', 'originRanking', 'upRanking']

const rankingStore = new HYEventStore({
  state: {
    upRanking: {}, //飙升榜
    hotRanking: {},  //热歌榜
    newRanking: {}, //新歌榜
    originRanking: {} //原创榜
  },
  actions: {
    getRankingData: function(ctx, payload) {
      for (let i = 0; i < 4; i++) {
        const index = i
        getRankings(index).then(res => {
          const rankName = rankingMap[index]
          ctx[rankName] = res.playlist
        })
      }
    }
  }
})

export {
  rankingStore
}